/**
 * ship-device edit
 */
let _this;
let _loading;
// new Vue({
//     el: '#appContainVue',
//     data: {
//         size: '',
//         deviceStatus:'',
//         isTimeGroup: false,
//         loginU: {},
//         viewData: {},
//         levelArray: [],
//         levelData: [],
//         levelAllData: []
//     },
//     mounted() {
//         _this = this;
//         let u = localStorage.getItem("ADMIN_LOGIN");
//         let loginU = decryptLocalStorage(u);
//         this.loginU = loginU;
//         let _data = localStorage.getItem("workCardData");
//         if (_data != undefined) {
//             let viewData = decryptLocalStorage(_data, loginU.token);
//             console.log(viewData);
//             if (viewData.workSystem == '2') {
//                 this.isTimeGroup = true;
//             }
//         }
//     },
//     methods: {
//
//     }
// });
let shipId = "";shipName="";
layui.use(['form', 'tableSelect', 'layedit', 'laydate'], function () {
    let form,layer,tableSelect,layedit,laydate,$;
    form = layui.form,
        layer = layui.layer,
        tableSelect = layui.tableSelect,
        layedit = layui.layedit,
        laydate = layui.laydate,
        $ = layui.$;


    let u = localStorage.getItem("ADMIN_LOGIN");
    let loginU = {};
    if (u == undefined) {
        layer.msg('请登录', {icon: 1, time: 500}, function () {
            window.location = 'page/login.html';
        });
    } else {
        loginU = decryptLocalStorage(u);
    }
    // if(loginU.shipId!=0){
    //     shipId=loginU.shipId
    // }
    let _data = localStorage.getItem("movieServerData");
    let viewData = undefined;

    if (_data != undefined) {
        viewData = decryptLocalStorage(_data, loginU.token);
        $("#shipId").val(viewData.shipId);
        $("#shipName").val(viewData.shipName);
        $("#serverUrl").val(viewData.serverUrl);
        $("#shoreUrl").val(viewData.shoreUrl);
        $("#sonicWallName").val(viewData.sonicWallName);
        $("#sonicWallIp").val(viewData.sonicWallIp);
        $("#sonicWallPort").val(viewData.sonicWallPort);
        $("#sonicWallUserName").val(viewData.sonicWallUserName);
        $("#sonicWallPassword").val(viewData.sonicWallPassword);
    }
    loadShip();
    //监听提交
    form.on('submit(saveBtn)', function (data) {
        var params = data.field;
        params.token = loginU.token;
        //添加
        if (viewData == undefined) {
            request.add('movieServer', JSON.stringify(params), function (result) {
                if (result.code == 0) {
                    layer.msg('保存成功', {
                        icon: 1,
                        time: 500
                    }, function () {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });

                } else {
                    layer.msg(result.msg || '保存失败', {
                        icon: 2,
                        time: 2000
                    });
                }
            });
        }
        //修改
        else {
            params.serverId = viewData.serverId;
            request.update('movieServer', JSON.stringify(params), function (result) {
                if (result.code == 0) {
                    layer.msg('保存成功', {
                        icon: 1,
                        time: 500
                    }, function () {
                        // 关闭弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });

                } else {
                    layer.msg(result.msg || '保存失败', {
                        icon: 2,
                        time: 2000
                    });
                }
            });
        }

        return false;
    });


    //ship
    function loadShip() {
        let tableUrl = "/admin/v1/ship/page?shipStatus=营运&token=" + loginU.token;
        tableSelect.render({
            elem: '#shipName',
            checkedKey: 'id',
            searchFlag: true,
            searchKey: 'shipName',
            where: {
                keyWork: JSON.stringify({shipId: 0})
            },
            table: {
                url: tableUrl,loginUserType:loginU.userType,
                cols: [[
                    {type: 'radio'},
                    {field: 'shipId', title: 'ID'},
                    {field: 'shipCompanyName', title: '船舶公司'},
                    {field: 'shipName', title: '船舶'}
                ]]
            },
            done: function (elem, data) {
                if (data.data.length > 0) {
                    shipId = data.data[0].shipId;
                    $("#shipId").val(data.data[0].shipId);
                    $("#shipName").val(data.data[0].shipName);
                }
            },
            clear: function () {
                shipId = "";
                $("#shipId").val("");
                $("#shipName").val("");
            }
        })
    }


});
